<!--
 * @Author: Luxiaoxiang
 * @Date: 2022-10-11 22:42:44
 * @LastEditors: lxx
 * @LastEditTime: 2022-10-24 17:02:31
 * @Description:
 * @FilePath: \briup-ui\src\pages\admin\check\Certification.vue
-->
<template>
  <!-- 员工实名认证审核 -->
  <div>
    <!-- 实名认证 -->
    <!-- 第一行 表单控件 -->
    <div class="header" style="display:flex">
      <el-date-picker
        v-model="time"
        type="datetimerange"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        align="right"
        value-format="timestamp"
        @change="selectDate"
      />
      <el-form :inline="true" :model="params" class="demo-form-inline" style="margin-left: 10px">
        <el-form-item>
          <el-select v-model="params.status" placeholder="请选择状态" clearable>
            <el-option label="通过" value="通过" />
            <el-option label="不通过" value="不通过" />
            <el-option label="未审核" value="未审核" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="params.userId" placeholder="申请人编号" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 第一行 表单控件结束 -->

    <!-- 第二行 表格 -->
    <el-table :data="userData">
      <el-table-column type="index" :index="1" label="序号" />
      <el-table-column prop="userId" label="申请人编号" />
      <el-table-column prop="realname" label="姓名" />
      <el-table-column prop="applyTime" label="申请时间">
        <template slot-scope="scope">
          <span>{{ scope.row.applyTime |fmtDate }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="idCard" label="身份证号" style="width: 200px" />
      <el-table-column prop="idcardPhotoPositive" label="身份证正面" >
        <template slot-scope="scope">
          <el-popover placement="right" trigger="hover">
            <img
              slot="reference"
              :src="scope.row.idcardPhotoPositive"
              alt="加载失败"
              width="40px"
            >
            <img width="100px" height="100px" :src="scope.row.idcardPhotoPositive" alt="">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="idcardPhotoNegative" label="身份证反面">
        <template slot-scope="scope">
          <el-popover placement="right" trigger="hover">
            <img
              slot="reference"
              :src="scope.row.idcardPhotoNegative"
              alt="加载失败"
              width="40px"
            >
            <img width="100px" height="100px" :src="scope.row.idcardPhotoNegative" alt="">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="bankCard" label="银行卡号"  />

      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">

          <span v-if="scope.row.status == '通过'" class="pass">通过</span>
          <span v-else class="unpass">不通过</span>

        </template>
      </el-table-column>
      <el-table-column label="审核">
        <template slot-scope="scope">
          <a
            v-if="scope.row.status == '通过'"
            href="#"
            @click.prevent="changeStatus(scope.row.id, '不通过')"
          >
            <el-tag type="danger">不通过</el-tag>

          </a>
          <a
            v-else
            href="#"

            @click.prevent="changeStatus(scope.row.id, '通过')"
          >
            <el-tag >通过</el-tag>
          </a>
        </template>
      </el-table-column>
    </el-table>
    <!-- 第二行 表格结束 -->

    <div class="bottom">
      <el-pagination
        class="page"
        :current-page="params.page"
        :page-sizes="[2, 5, 10, 20, 30]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />

    </div>

  </div>
</template>

<script>
import { fmtDate } from '@/filters'
import { log } from '@antv/g2plot/lib/utils'
import { getDate, onLine, offLine } from '../../../api/certification'
export default {
  data() {
    return {
      time: [],
      beginTime: '',
      endTime: '',

      // 日期
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 4600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      params: {
        page: 1,
        pageSize: 10
      },
      userData: [],
      total: 0
    }
  },
  computed: {},
  created() {
    this.getDates()
  },
  mounted() {},
  methods: {
    toSearch() {
      this.params.page = 1
      this.getDates()
    },
    async getDates() {
      for (const key in this.params) {
        if (!this.params[key]) {
          delete this.params[key]
        }
      }
      if (this.beginTime && this.endTime) {
        this.params.beginTime = this.beginTime
        this.params.endTime = this.endTime
      }
      const res = await getDate(this.params)
      console.log(res,'ccccc')
      this.userData = res.data.list
      this.total = res.data.total
    },

    // 页码条数发生改变的方法 默认参数pageSize
    handleSizeChange(pageSize) {
      // 当前页码发生改变的方法
      this.params.pageSize = pageSize
      this.params.page = 1
      this.getDates()
    },
    // 当前页码发生改变的方法 默认参数页码page
    handleCurrentChange(page) {
      this.params.page = page
      this.getDates()
    },
    changeStatus(id, status) {
      this.$confirm('此操作将改变用户的状态，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        if (status === '通过') {
          const res = await onLine({ id })
          this.$message({
            type: 'success',
            message: res.message
          })
        } else {
          const res = await offLine({ id })
          this.$message({
            type: 'success',
            message: res.message
          })
        }
        // 刷新页面
        this.getDates()
      })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消我们的操作'
          })
        })
    },
    selectDate() {
      if (this.time === null) {
        this.time = []
        this.beginTime = undefined
        this.endTime = undefined
      } else {
        this.beginTime = this.time[0]
        this.endTime = this.time[1]
      }
    }
  }
}
</script>
<style lang="scss">
$color: #30b08f;
.bottom{
text-align: center;
margin-top: 30px;
}

.pass {
  color: $color;
}
.unpass {
  color: #e65d6e;
}
</style>
